package com.chcit.mobile.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chcit.mobile.R;
import com.chcit.mobile.helper.recycler.BaseSelectQuickAdapter;
import com.chcit.mobile.mvp.model.entity.ShipmentBean;

import java.util.List;

public class ShipmentAdapter extends BaseSelectQuickAdapter<ShipmentBean,BaseViewHolder> {

    private View.OnClickListener mOnClickListener;
    public ShipmentAdapter(@Nullable List<ShipmentBean> data) {
        super(R.layout.item_shipment_data,data);


    }

    public void setOnClickListener(View.OnClickListener onClickListener){
        mOnClickListener = onClickListener;
    }
    @Override
    protected void convert(final BaseViewHolder helper, final ShipmentBean item) {

        CheckBox checkBox = helper.getView(R.id.box_shipment_select);
        int position= helper.getAdapterPosition();
        checkBox.setChecked(mSelectedPositions.get(position));
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int i= helper.getAdapterPosition();
                if (isItemChecked(i)) {
                    setItemChecked(i, false);
                } else {
                    setItemChecked(i, true);
                }

                if (mTitleBarView != null) {
                    String msg = "已选择" + getSelectedItem().size() + "/" + getItemCount();
                    mTitleBarView.setText(msg);
                }
                notifyItemChanged(i);
            }
        });
        LinearLayout l1 = helper.getView(R.id.ll_first);
        l1.setOnClickListener(v->{
            checkBox.performClick();
        });
        final TextView textView = helper.getView(R.id.tv_shipment_deal);
        textView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                if(mOnClickListener != null){
                    v.setTag(item);
                    mOnClickListener.onClick(v);
                }
            }
        });
        helper.setText(R.id.tv_shipment_GuaranteeDate,item.getGuaranteeDate());
        helper.setText(R.id.tv_shipment_Lot,item.getLot());
        helper.setText(R.id.tv_shipment_Manufacturer,item.getManufacturer());
        helper.setText(R.id.tv_shipment_pname,item.getProductName());
        helper.setText(R.id.tv_shipment_productSpec,item.getProductSpec());
        helper.setText(R.id.tv_shipment_QtyOnHand,item.getQtyLeft().toString());
        helper.setText(R.id.tv_shipment_StorageStatusName,item.getQtyTarget().toString());
        helper.setText(R.id.tv_shipment_VendorName,"门诊四楼");


    }



}
